/**
 * @author: ZhongXu
 * @date:2017-08-10
 */
$(document).ready(
    function() {
        var VAL = {
            NORMAL : "0000000",
            T_FPPFORCEIN : "FPPFORCEIN",
            T_FBPSWHPTH : "FBPSWHPTH",
            T_FBPLSTDAT : "FBPBISDAT",
            T_FIPINQBOX : "FIPINQBOX",
            T_FBPBISPTH : "FBPBISPTH",
//            EVT_USER :$("#userId").text(),
            EVT_USER    :"C1706004",
            DISABLED_ATTR : {
                'disabled' : true
            },
            ENABLED_ATTR : {
                'disabled' : false
            }
        };
        var domObj = {
            $boxIdFk : $("#boxIdFk"),
            $frPathIdFk : $("#frPathIdFk"),
            $boxId : $("#boxId"),
            $boxStat : $("#boxStat"),
            $prdQty : $("#prdQty"),
            $chipQty : $("#chipQty"),
            $crPathIdFk : $("#crPathIdFk"),
            $crPathVerFk : $("#crPathVerFk"),
            $crOpeNoFk : $("#crOpeNoFk"),
            $nxPathIdFk : $("#nxPathIdFk"),
            $nxPathVerFk : $("#nxPathVerFk"),
            $nxOpeNoFk : $("#nxOpeNoFk"),
            $acRecipeId : $("#acRecipeId"),
            $woIdFk : $("#woIdFk"),
            buttons : {
                //radio
                $radioOne : $("#radioOne"),
                $radioTwo : $("#radioTwo"),
                $radioThere : $("#radioThere"),
                //button按钮
                $query_btn : $("#query_btn"),
                $selectReason_btn : $("#selectReason_btn"),
                $deleteReason_btn : $("#deleteReason_btn"),
                $sure_btn : $("#sure_btn"),
                $cancel_btn : $("#cancel_btn"),
                $force_btn : $("#force_btn"),
                $stop_btn : $("#stop_btn"),
            },
            grids : {
                $reasonDiv : $("#reasonDiv"),
                $reasonListGrd : $("#reasonListGrd"),
                $reasonListDiv : $("#reasonListDiv"),
                $reasonListPg : $("#reasonListPg"),

                $glassListGrd : $("#glassListGrd"),
                $glassListDiv : $("#glassListDiv"),
                $glassListPg : $("#glassListPg")
            },
            dialogs : {
                $addReasonDialog : $("#addReasonDialog"),
                $rePathDialog : $("#rePathDialog"),
                $forcePathDialog : $("#forcePathDialog"),
                $deptId : $("#deptId"),

                $modalReasonListDiv : $("#modalReasonListDiv"),
                $modalReasonListGrd : $("#modalReasonListGrd"),
                $modalReasonListPg : $("#modalReasonListPg"),

                $reModalReasonListDiv : $("#reModalReasonListDiv"),
                $reModalReasonListGrd : $("#reModalReasonListGrd"),
                $reModalReasonListPg : $("#reModalReasonListPg"),

                // 对话框的确认按钮
                $reasonDialog_sureBtn : $("#reasonDialog_sureBtn"),
                $rePathDialog_sureBtn : $("#rePathDialog_sureBtn"),

                $rePathListDiv : $("#rePathListDiv"),
                $rePathListGrd : $("#rePathListGrd"),
                $rePathListPg : $("#rePathListPg"),
                $forcePathDialog_sureBtn : $("#forcePathDialog_sureBtn"),

                $forcePathListDiv : $("#forcePathListDiv"),
                $forcePathListGrd : $("#forcePathListGrd"),
                $forcePathListPg : $("#forcePathListPg"),
            }

        }
        //主页面button方法
        var btnFunc = {
            queryBtnfunc : function() {
//                clearDataAction();
                domObj.$frPathIdFk.empty();
                SelectDom.setSelect(domObj.$frPathIdFk, "");
                var boxIdFk, iary, inObj, outObj;
                boxIdFk = domObj.$boxIdFk.val();// 卡匣id
                if ("" == boxIdFk) {
                    showErrorDialog("", "卡匣代码不能为空，请输入卡匣代码");
                    return false;
                }
                iary = {
                    box_id : boxIdFk
                };
                inObj = {
                    trx_id : VAL.T_FIPINQBOX,
                    action_flg : "Q",
                    box_id : boxIdFk,
                    iary : [ iary ]
                };
                outObj = comTrxSubSendPostJson(inObj);
                if (outObj.rtn_code === VAL.NORMAL) {
                    if(outObj.box_stat!='WAIT'){
                        showErrorDialog("", "该卡匣不是WAIT状态");
                        return false;
                    }
                    var chip_qty;//计算面板数量
                    chip_qty=(outObj.prd_qty)*(outObj.oary[0].prd_qty);
                    // 初始化卡匣信息
                    domObj.$boxId.val(outObj.box_id);
                    domObj.$boxStat.val(outObj.box_stat);
                    domObj.$prdQty.val(outObj.prd_qty);
                    domObj.$chipQty.val(chip_qty);
                    domObj.$crPathIdFk
                        .val(outObj.oary[0].cr_path_id_fk);
                    domObj.$crPathVerFk
                        .val(outObj.oary[0].cr_path_ver_fk);
                    domObj.$crOpeNoFk
                        .val(outObj.oary[0].cr_ope_no_fk);
                    domObj.$nxPathIdFk.val(outObj.nx_path_id_fk);
                    domObj.$nxPathVerFk.val(outObj.nx_path_ver_fk);
                    domObj.$nxOpeNoFk.val(outObj.nx_ope_no_fk);
                    domObj.$acRecipeId
                        .val(outObj.oary[0].ac_recipe_id);
                    domObj.$woIdFk
                        .val(outObj.wo_id_fk);
                    // 初始化玻璃信息
                    setGridInfo(outObj.oary, "#glassListGrd");
                    // 初始化重工代码
                    var frPathIdFk, frPathVerFk, frOpeNoFk, swhTyp,iarys, inObjs, outObjs;
                    frPathIdFk  = outObj.oary[0].cr_path_id_fk;
                    frPathVerFk = outObj.oary[0].cr_path_ver_fk;
                    frOpeNoFk   = outObj.oary[0].cr_ope_no_fk;
                    if(domObj.buttons.$radioOne.prop('checked')){
                        swhTyp='R';
                    }else if(domObj.buttons.$radioTwo.prop('checked')){
                        swhTyp='K';
                    }else {
                        swhTyp='Q';
                    }
                    iarys = {
                        fr_path_id_fk : frPathIdFk,
                        fr_path_ver_fk : frPathVerFk,
                        fr_ope_no_fk : frOpeNoFk,
                        swh_typ : swhTyp
                    };
                    inObjs = {
                        trx_id : VAL.T_FBPSWHPTH,
                        action_flg : "Q",
                        iary : [ iarys ]
                    };
                    outObjs = comTrxSubSendPostJson(inObjs);
                    if (outObjs.rtn_code === VAL.NORMAL) {
                        setGridInfo(outObjs.oary, "#rePathListGrd");
                    }
                }
            },
            selectReasonBtnfunc : function() {
                domObj.dialogs.$modalReasonListGrd
                    .jqGrid("clearGridData");
                domObj.dialogs.$reModalReasonListGrd
                    .jqGrid("clearGridData");
                // 原因代码对话框的模型
                domObj.dialogs.$addReasonDialog.modal({
                    backdrop : true,
                    keyboard : false,
                    show : false
                });
                domObj.dialogs.$addReasonDialog.modal("show");
                comAddValueByDataCateFnc("#deptId","DEPT","data_ext","data_ext",true);
                var deptId, iary, inObj, outObj;
                iary = {
                    data_cate : "RKRS",
                };
                inObj = {
                    trx_id : VAL.T_FBPLSTDAT,
                    action_flg : "Q",
                    iary : [ iary ]
                };
                outObj = comTrxSubSendPostJson(inObj);
                if (outObj.rtn_code === VAL.NORMAL) {
                    setGridInfo(outObj.oary,"#modalReasonListGrd");
                }
            },
            deleteReasonBtnfunc : function() {
                var selRowId = domObj.grids.$reasonListGrd.jqGrid(
                    "getGridParam", "selrow");
                if (selRowId==null||selRowId.length < 1) {
                    showErrorDialog("", "请至少选择一条原因代码进行删除");
                    return false;
                }
                $("#deleteReason_btn").showCallBackWarnningDialog({
                    errMsg : "是否删选原因代码,请确认!!!!",
                    callbackFn : function(data) {
                        if (data.result == true) {
                            // 动态删除jqgrid行时，数据会在动态变化
                            var length = selRowId.length;
                            for (var i = 0; i < length; i++) {
                                domObj.grids.$reasonListGrd.jqGrid("delRowData",selRowId[0]);
                            }
                        }
                    }
                });
            },
            sureBtnfunc: function() {
                var boxId,crPathIdFk, crPathVerFk,crOpeNoFk,
                    swhId,swhTyp,swhPathIdFk,swhPathVerk,evtUsr,
                    outPathIdFk,outPathVerFk,outOpeNoFk,rsnCate,rsnCode,rsnDept,iary,inObj,outObj;

                boxId = domObj.$boxIdFk.val();
                if (!boxId) {
                    showErrorDialog("", "卡匣代码不能为空");
                    return false;
                }
                var swh_id = domObj.$frPathIdFk.val();
                if(!swh_id){
                    showErrorDialog("", "重工代码不能为空");
                    return;
                }
                var rowIds = domObj.grids.$glassListGrd.jqGrid("getGridParam","selarrrow");
                var data = new Array();
                for (var i=0;i<rowIds.length;i++){
                    var rowData = domObj.grids.$glassListGrd.jqGrid("getRowData",rowIds[i]);
                    data.push(rowData)
                }
                if (data.length<1) {
                    showErrorDialog("", "至少选中一条玻璃信息");
                    return false;
                }

                if(domObj.buttons.$radioTwo.prop('checked')){
                    var reasonRowData =domObj.grids.$reasonListGrd.jqGrid("getRowData");
                    if(reasonRowData.length<1){
                        showErrorDialog("", "原因代码不能为空");
                        return;
                    }
                }
                var rowId= domObj.dialogs.$rePathListGrd.jqGrid("getGridParam", "selrow");
                var pathRowData = domObj.dialogs.$rePathListGrd.jqGrid("getRowData",rowId);
                var iarys,inObjs,outObjs;//查询在不在主途程上
                iaryA = {
                    path_id : domObj.$nxPathIdFk.val(),
                    path_ver : domObj.$nxPathVerFk.val()
                };
                inObjs = {
                    trx_id : VAL.T_FBPBISPTH,
                    action_flg : "Q",
                    iaryA : [ iaryA ]
                };
                outObjs = comTrxSubSendPostJson(inObjs);
                if (outObjs.rtn_code === VAL.NORMAL) {
                    if(outObjs.oaryA[0].path_cate!='MAN'){
                        showErrorDialog("", "该卡匣不在主流程上，无法进行该操作");
                        return false;
                    }
                }
                swhId = pathRowData.swh_id;
                if (!swhId) {
                    showErrorDialog("", "分支代码不能为空1");
                    return false;
                }
                if(domObj.buttons.$radioOne.prop('checked')){
                    swhTyp='R';
                }else if(domObj.buttons.$radioTwo.prop('checked')){
                    swhTyp='K';
                }else {
                    swhTyp='Q';
                }
                swhPathIdFk=pathRowData.swh_path_id_fk;
                if (!swhPathIdFk) {
                    showErrorDialog("", "分支工艺名称不能为空");
                    return false;
                }
                swhPathVerk=pathRowData.swh_path_ver_fk;
                if (!swhPathVerk) {
                    showErrorDialog("", "分支工艺路线不能为空");
                    return false;
                }
                if(domObj.buttons.$radioTwo.prop('checked')) {
                    rsnCode = reasonRowData[0].deptId;
                    if (!rsnCode) {
                        showErrorDialog("", "部门代码不能为空,请输入");
                        return false;
                    }
                    rsnCate = "RKRS";
                    rsnDept = reasonRowData[0].data_ext;
                    if (!rsnDept) {
                        showErrorDialog("", "原因代码不能为空,请输入");
                        return false;
                    }
                }
                crPathIdFk = domObj.$crPathIdFk.val();
                if (!crPathIdFk) {
                    showErrorDialog("", "当前工艺路线不能为空");
                    return false;
                }
                crPathVerFk = domObj.$crPathVerFk.val();
                if (!crPathVerFk) {
                    showErrorDialog("", "当前工艺版本不能为空");
                    return false;
                }
                crOpeNoFk = domObj.$crOpeNoFk.val();
                if (!crOpeNoFk) {
                    showErrorDialog("", "当前站点不能为空");
                    return false;
                }
                outPathIdFk = pathRowData.out_path_id_fk;
                if (!outPathIdFk) {
                    showErrorDialog("", "转出工艺路线不能为空");
                    return false;
                }
                outPathVerFk = pathRowData.out_path_ver_fk;
                if (!outPathIdFk) {
                    showErrorDialog("", "转出工艺版本不能为空");
                    return false;
                }
                outOpeNoFk = pathRowData.out_ope_no_fk;
                if (!outOpeNoFk) {
                    showErrorDialog("", "转出站点不能为空");
                    return false;
                }
                if (!VAL.EVT_USER) {
                    showErrorDialog("", "操作人信息不能为空");
                    return false;
                }
                iary = {
                    box_id : boxId,
                    swh_id : swhId,
                    swh_typ: swhTyp,
                    swh_path_id_fk  : swhPathIdFk,
                    swh_path_ver_fk : swhPathVerk,
                    rsn_code       : rsnCode,
                    rsn_cate       : rsnCate,
                    rsn_dept       : rsnDept,
                    cr_path_id_fk  : crPathIdFk,
                    cr_path_ver_fk : crPathVerFk,
                    cr_ope_no_fk   : crOpeNoFk,
                    out_path_id_fk  : outPathIdFk,
                    out_path_ver_fk : outPathVerFk,
                    out_ope_no_fk   : outOpeNoFk,
                    ret_prd_info   : data,
                    evt_usr        : VAL.EVT_USER,
                };
                inObj = {
                    trx_id : VAL.T_FPPFORCEIN,
                    action_flg : "R",
                    iary : [iary]
                };
                outObj = comTrxSubSendPostJson(inObj);
                if (outObj.rtn_code === VAL.NORMAL) {
                    if(domObj.buttons.$radioOne.prop('checked')){
                        showSuccessDialog("进入修补成功");
                    }else if(domObj.buttons.$radioTwo.prop('checked')){
                        showSuccessDialog("进入重工成功");
                    }else {
                        showSuccessDialog("进入OQC成功");
                    }
                    btnFunc.queryBtnfunc();//更新信息
                }
            },
            cancelBtnfunc : function() {
                var boxId,swhTyp,nxPathIdFk,nxPathVerFk,nxOpeNoFk,crPathIdFk, crPathVerFk,
                    crOpeNoFk,rsnCode,rsnCate,rsnDept,iary,inObj,outObj;

                boxId = domObj.$boxIdFk.val();

                if(domObj.buttons.$radioTwo.prop('checked')){
                    var reasonRowData =domObj.grids.$reasonListGrd.jqGrid("getRowData");
                    if(reasonRowData.length<1){
                        showErrorDialog("", "原因代码不能为空");
                        return;
                    }
                }
                var rowIds = domObj.grids.$glassListGrd.jqGrid("getGridParam","selarrrow");
                if (!boxId) {
                    showErrorDialog("", "卡匣代码不能为空");
                    return false;
                };
                // for (var i=0;i<rowIds.length;i++){
                //     var rowData = domObj.grids.$glassListGrd.jqGrid("getRowData",rowIds[i]);
                //     data.push(rowData)
                // }
                // if (data.length<1) {
                //     showErrorDialog("", "至少选中一条玻璃信息");
                //     return false;
                // }
                boxId = domObj.$boxIdFk.val();
                if(domObj.buttons.$radioOne.prop('checked')){
                    swhTyp='R';
                }else if(domObj.buttons.$radioTwo.prop('checked')){
                    swhTyp='K';
                }else {
                    swhTyp='Q';
                }
                nxPathIdFk = domObj.$nxPathIdFk.val();
                nxPathVerFk = domObj.$nxPathVerFk.val();
                nxOpeNoFk = domObj.$nxOpeNoFk.val();
                crPathIdFk = domObj.$crPathIdFk.val();
                crPathVerFk = domObj.$crPathVerFk.val();
                crOpeNoFk = domObj.$crOpeNoFk.val();
                if (!crPathIdFk) {
                    showErrorDialog("", "当前工艺路线不能为空");
                    return false;
                }
                if (!crPathVerFk) {
                    showErrorDialog("", "当前工艺版本不能为空");
                    return false;
                }
                if (!crOpeNoFk) {
                    showErrorDialog("", "当前站点不能为空");
                    return false;
                }
                if (!nxPathIdFk) {
                    showErrorDialog("", "下一站工艺路线不能为空");
                    return false;
                }
                if (!nxPathIdFk) {
                    showErrorDialog("", "下一站工艺版本不能为空");
                    return false;
                }
                if (!nxOpeNoFk) {
                    showErrorDialog("", "下一站站点不能为空");
                    return false;
                }
                if(domObj.buttons.$radioTwo.prop('checked')) {
                    rsnCode = reasonRowData[0].deptId;
                    if (!rsnCode) {
                        showErrorDialog("", "部门代码不能为空,请输入");
                        return false;
                    }
                    rsnCate = "RKRS";
                    rsnDept = reasonRowData[0].data_ext;
                    if (!rsnDept) {
                        showErrorDialog("", "原因代码不能为空,请输入");
                        return false;
                    }
                }
                iary = {
                    box_id : boxId,
                    swh_typ: swhTyp,
                    nx_path_id_fk  : nxPathIdFk,
                    nx_path_ver_fk : nxPathVerFk,
                    nx_ope_no_fk   : nxOpeNoFk,
                    cr_path_id_fk  : crPathIdFk,
                    cr_path_ver_fk : crPathVerFk,
                    cr_ope_no_fk   : crOpeNoFk,
                    rsn_code       : rsnCode,
                    rsn_cate       : rsnCate,
                    rsn_dept       : rsnDept,
                    // ret_prd_info   : data,
                    evt_usr        : VAL.EVT_USER
                };
                inObj = {
                    trx_id : VAL.T_FPPFORCEIN,
                    action_flg : "C",
                    iary : [iary]
                };
                outObj = comTrxSubSendPostJson(inObj);
                if (outObj.rtn_code === VAL.NORMAL) {
                    if(domObj.buttons.$radioOne.prop('checked')){
                        showSuccessDialog("取消修补成功");
                    }else if(domObj.buttons.$radioTwo.prop('checked')){
                        showSuccessDialog("取消重工成功");
                    }else {
                        showSuccessDialog("取消OQC成功");
                    }
                    btnFunc.queryBtnfunc();//更新信息
                }
            },
            forceBtnfunc : function() {
                var box_id = domObj.$boxId.val().trim();
                if (!box_id) {
                    showErrorDialog("", "卡匣代码不能为空");
                    return false;
                }
                if(domObj.buttons.$radioTwo.prop('checked')){
                    var reasonRowData =domObj.grids.$reasonListGrd.jqGrid("getRowData");
                    if(reasonRowData.length<1){
                        showErrorDialog("", "原因代码不能为空");
                        return;
                    }
                }
                var rowIds = domObj.grids.$glassListGrd.jqGrid("getGridParam","selarrrow");
                if (rowIds.length<1) {
                    showErrorDialog("", "至少选中一条玻璃信息");
                    return false;
                }
                var path_cate="";
                domObj.dialogs.$forcePathDialog.modal({
                    backdrop : true,
                    keyboard : false,
                    show : false
                });

                domObj.dialogs.$forcePathDialog.modal("show");
                if(domObj.buttons.$radioOne.prop('checked')){
                    path_cate="REP";
                }else if(domObj.buttons.$radioTwo.prop('checked')){
                    path_cate="RWK";
                }else if(domObj.buttons.$radioThere.prop('checked')){
                    path_cate="OQC";
                }

                var inObjs = {
                    trx_id : VAL.T_FBPBISPTH,
                    action_flg : "Q",
                    iaryA : [{
                        path_cate : path_cate
                    }]
                };
                var  outObjs = comTrxSubSendPostJson(inObjs);
                if(outObjs.rtn_code == VAL.NORMAL){
                    setGridInfo(outObjs.oaryA, "#forcePathListGrd");
                }


            },
            stopBtnfunc : function() {
                var boxId, swhTyp,crPathIdFk,crOpeNoFk,crPathVerFk,rsnCode, rsnCate,iary,rsnDept,inObj,outObj;

                boxId = domObj.$boxIdFk.val();
                if (!boxId) {
                    showErrorDialog("", "卡匣代码不能为空");
                    return false;
                }
                if(domObj.buttons.$radioTwo.prop('checked')){
                    var reasonRowData =domObj.grids.$reasonListGrd.jqGrid("getRowData");
                    if(reasonRowData.length<1){
                        showErrorDialog("", "原因代码不能为空");
                        return;
                    }
                }
                var rowIds = domObj.grids.$glassListGrd.jqGrid("getGridParam","selarrrow");
                var data = new Array();
                for (var i=0;i<rowIds.length;i++){
                    var rowData = domObj.grids.$glassListGrd.jqGrid("getRowData",rowIds[i]);
                    data.push(rowData)
                }
                if (data.length<1) {
                    showErrorDialog("", "至少选中一条玻璃信息");
                    return false;
                }

                if(domObj.buttons.$radioOne.prop('checked')){
                    swhTyp='R';
                }else if(domObj.buttons.$radioTwo.prop('checked')){
                    swhTyp='K';
                }else {
                    swhTyp='Q';
                }
                crPathIdFk = domObj.$crPathIdFk.val();
                crPathVerFk = domObj.$crPathVerFk.val();
                crOpeNoFk = domObj.$crOpeNoFk.val();
                if(domObj.buttons.$radioTwo.prop('checked')) {
                    rsnCode = reasonRowData[0].deptId;
                    if (!rsnCode) {
                        showErrorDialog("", "部门代码不能为空,请输入");
                        return false;
                    }
                    rsnCate = "RKRS";
                    rsnDept = reasonRowData[0].data_ext;
                    if (!rsnDept) {
                        showErrorDialog("", "原因代码不能为空,请输入");
                        return false;
                    }
                }
                if (! boxId) {
                    showErrorDialog("", "卡匣代码不能为空");
                    return false;
                }
//                if (!rsnCode) {
//                    showErrorDialog("", "部门代码不能为空,请输入");
//                    return false;
//                }
//                if (!rsnDept) {
//                    showErrorDialog("", "原因代码不能为空,请输入");
//                    return false;
//                }
                if (!crPathIdFk) {
                    showErrorDialog("", "当前工艺路线不能为空");
                    return false;
                }
                if (!crPathVerFk) {
                    showErrorDialog("", "当前工艺版本不能为空");
                    return false;
                }
                if (!crOpeNoFk) {
                    showErrorDialog("", "当前站点不能为空");
                    return false;
                }
                iary = {
                    box_id : boxId,
                    swh_typ: swhTyp,
                    rsn_code       : rsnCode,
                    rsn_cate       : rsnCate,
                    rsn_dept       : rsnDept,
                    cr_path_id_fk  : crPathIdFk,
                    cr_path_ver_fk : crPathVerFk,
                    cr_ope_no_fk   : crOpeNoFk,
                    ret_prd_info   : data,
                    evt_usr        : VAL.EVT_USER,
                };
                inObj = {
                    trx_id : VAL.T_FPPFORCEIN,
                    action_flg : "A",
                    iary : [iary]
                };
                outObj = comTrxSubSendPostJson(inObj);
                if (outObj.rtn_code === VAL.NORMAL) {
                    if(swhTyp='R'){
                        showSuccessDialog("终止修补成功！");
                    }else if(swhTyp='K'){
                        showSuccessDialog("成功终止重工！")
                    }else{
                        showSuccessDialog("终止OQC成功！")
                    }
                    btnFunc.queryBtnfunc();//更新信息
                }
            }
        }
        //主页面grid初始化
        var iniGridInfo = function() {
            domObj.grids.$reasonListGrd.jqGrid({
                url : "",
                datatype : "local",
                mtype : "POST",
                // height :  $(window).height() - 700,
                height :$(window).height()*0.15,
                width : domObj.grids.$reasonListDiv.width(),
                autowidth : true,
                shrinkToFit : true,
                resizable : true,
                loadonce : true,
                viewrecords : true,
                rownumbers : true,
                rowNum : 20,
                emptyrecords : true,
                multiselect : false,
                pager : domObj.grids.$reasonListPg,
                colModel : [ {
                    name : 'deptId',
                    index : 'deptId',
                    label : '部门代码',
                    width : 250
                },{
                    name : 'data_ext',
                    index : 'data_ext',
                    label : '原因代码',
                    width : 250
                }, {
                    name : 'data_desc',
                    index : 'data_desc',
                    label : '原因代码说明',
                    width : 450
                },]
            });

            domObj.grids.$glassListGrd.jqGrid({
                url : "",
                datatype : "local",
                mtype : "POST",
                height:$(window).height()*0.4,
                // autoheight : true,
                width : domObj.grids.$glassListDiv.width(),
                autowidth : true,
                shrinkToFit : false,
                resizable : true,
                loadonce : true,
                viewrecords : true,
                rownumbers : true,
                rowNum : 20,
                emptyrecords : true,
                multiselect : true,
                pager : domObj.grids.$glassListPg,
                colModel : [ {
                    name : 'prd_seq_id',
                    index : 'prd_seq_id',
                    label : '玻璃代码',
                    width : 150
                }, {
                    name : 'slot_no',
                    index : 'slot_no',
                    label : '子格位',
                    width : 150
                }, {
                    name : 'prd_stat',
                    index : 'prd_stat',
                    label : '玻璃状态',
                    width : 115
                }, {
                    name : 'prd_qty',
                    index : 'prd_qty',
                    label : '面板数量',
                    width : 115
                }, {
                    name : 'box_id_fk',
                    index : 'box_id_fk',
                    label : '卡匣代码',
                    width : 150
                }, {
                    name : 'prd_grade',
                    index : 'prd_grade',
                    label : '大板等级',
                    width : 115
                }, {
                    name : 'wo_id_fk',
                    index : 'wo_id_fk',
                    label : '工单信息',
                    width : 150
                }]
            });
        }
        //dailog对话框grid初始化
        var inModelGrid = function() {
            domObj.dialogs.$modalReasonListGrd
                .jqGrid("clearGridData");
            domObj.dialogs.$reModalReasonListGrd
                .jqGrid("clearGridData");
            domObj.dialogs.$rePathListGrd.jqGrid({
                url : "",
                datatype : "local",
                mtype : "POST",
                height : 300,
                // width:domObj.dialogs.rePathListDiv.width()* 0.99,
                width : 650,
                autowidth : false,
                shrinkToFit : false,
                resizable : true,
                loadonce : true,
                viewrecords : true,
                rownumbers : true,
                rowNum : 20,
                emptyrecords : true,
                multiselect : false,
                pager : domObj.dialogs.$rePathListPg,
                colModel : [{
                    name : 'swh_id',
                    index : 'swh_id',
                    label : '分支号码',
                    width : 100
                }, {
                    name : 'fr_ope_no_fk',
                    index : 'fr_ope_no_fk',
                    label : '分支站点',
                    width : 100,
                    hidden: true
                }, {
                    name : 'swh_path_id_fk',
                    index : 'swh_path_id_fk',
                    label : '分支工艺名称',
                    width : 100
                }, {
                    name : 'swh_path_ver_fk',
                    index : 'swh_path_ver_fk',
                    label : '分支工艺路线版本',
                    width : 100
                }, {
                    name : 'out_path_id_fk',
                    index : 'out_path_id_fk',
                    label : '转出工艺路线名称',
                    width : 100
                }, {
                    name : 'out_path_ver_fk',
                    index : 'out_path_ver_fk',
                    label : '转出工艺路线版本',
                    width : 100
                }, {
                    name : 'out_ope_no_fk',
                    index : 'out_ope_no_fk',
                    label : '转出工艺站点代码',
                    width : 100
                } ],
            });
            domObj.dialogs.$forcePathListGrd.jqGrid({
                url : "",
                datatype : "local",
                mtype : "POST",
                height : 300,
                // width:domObj.dialogs.rePathListDiv.width()* 0.99,
                width : 450,
                autowidth : false,
                shrinkToFit : false,
                resizable : true,
                loadonce : true,
                viewrecords : true,
                rownumbers : true,
                rowNum : 20,
                emptyrecords : true,
                multiselect : false,
                pager : domObj.dialogs.$forcePathListPg,
                colModel : [{
                    name : 'path_cate',
                    index : 'path_cate',
                    label : '工艺路线类型',
                    width : 100
                }, {
                    name : 'path_id',
                    index : 'path_id',
                    label : '工艺路线代码',
                    width : 180,
                }, {
                    name : 'path_ver',
                    index : 'path_ver',
                    label : '工艺路线版本',
                    width : 120
                }],
            });
            domObj.dialogs.$modalReasonListGrd
                .jqGrid({
                    url : "",
                    datatype : "local",
                    mtype : "POST",
                    height : 300,
                    // width :
                    // domObj.dialogs.$modalReasonListDiv.width()*0.99,
                    width : 400,
                    autowidth : false,
                    shrinkToFit : false,
                    resizable : true,
                    loadonce : true,
                    viewrecords : true,
                    rownumbers : true,
                    rowNum : 20,
                    emptyrecords : true,
                    multiselect : false,
                    pager : domObj.dialogs.$modalReasonListPg,
                    colModel : [ {
                        name : 'data_ext',
                        index : 'data_ext',
                        label : '原因代码',
                        width : 150
                    }, {
                        name : 'data_desc',
                        index : 'data_desc',
                        label : '原因代码说明',
                        width : 180
                    } ],
                    onSelectRow : function(rowId, status) {
                        var deptId = domObj.dialogs.$deptId.val();
                        if(!deptId){
                            showErrorDialog("", "请选择部门代码");
                            return false;
                        }
                        var rowId= domObj.dialogs.$modalReasonListGrd
                            .jqGrid("getGridParam", "selrow");
                        var rowData = domObj.dialogs.$modalReasonListGrd.jqGrid(
                            "getRowData", rowId);
                        rowData.deptId = deptId;
                        setGridInfo(rowData, "#reModalReasonListGrd");
                    }
                });

            domObj.dialogs.$reModalReasonListGrd.jqGrid({
                url : "",
                datatype : "local",
                mtype : "POST",
                height : 400,
                //width:domObj.dialogs.$reModalReasonListDiv.width()*0.99,
                width : 400,
                autowidth : false,
                shrinkToFit : false,
                resizable : true,
                loadonce : true,
                viewrecords : true,
                rownumbers : true,
                rowNum : 20,
                emptyrecords : true,
                multiselect  : false,
                pager : domObj.dialogs.$reModalReasonListPg,
                colModel : [ {
                    name : 'deptId',
                    index : 'deptId',
                    label : '部门代码',
                    width : 100
                }, {
                    name : 'data_ext',
                    index : 'data_ext',
                    label : '原因代码',
                    width : 100
                }, {
                    name : 'data_desc',
                    index : 'data_desc',
                    label : '原因代码说明',
                    width : 100,
                } ]
            });
        }
        // 选中重工代码的事件
        domObj.$frPathIdFk.on("select2:opening",function(e) {
            domObj.dialogs.$rePathDialog.modal({
                backdrop : true,
                keyboard : false,
                show : false
            });
            domObj.dialogs.$rePathDialog.modal("show");
        });
        //对话框的button方法
        var dialogFnc = {
            reasonSureFnc : function() {
                var Data = domObj.dialogs.$reModalReasonListGrd.jqGrid("getRowData");
                if(Data.length<1){
                    showErrorDialog("", "请选择一条原因代码");
                    return false;
                }
                setGridInfo(Data, "#reasonListGrd");
                domObj.dialogs.$addReasonDialog.modal("hide");
            },
            rePathSureFnc : function() {
                var rowId= domObj.dialogs.$rePathListGrd
                    .jqGrid("getGridParam", "selrow");
                if(rowId==null){
                    showErrorDialog("", "请选择一条重工代码");
                    return false;
                }
                rowData = domObj.dialogs.$rePathListGrd.jqGrid(
                    "getRowData", rowId);
                SelectDom.setSelect(domObj.$frPathIdFk,
                    rowData.swh_id);
                domObj.dialogs.$rePathDialog.modal("hide");
            },
            forcePathSureFnc : function(){

                var boxId, nx_path_id_fk, nx_path_ver_fk, rsnCate,rsnCode,rsnDept
                var iary,inObj,outObj;

                boxId = domObj.$boxId.val();
                if (!boxId) {
                    showErrorDialog("", "卡匣代码不能为空");
                    return false;
                }
                if(domObj.buttons.$radioTwo.prop('checked')){
                    var reasonRowData =domObj.grids.$reasonListGrd.jqGrid("getRowData");
                    if(reasonRowData.length<1){
                        showErrorDialog("", "原因代码不能为空");
                        return;
                    }
                }
                var rowId= domObj.dialogs.$forcePathListGrd.jqGrid("getGridParam", "selrow");
                var pathRowData = domObj.dialogs.$forcePathListGrd.jqGrid("getRowData",rowId);
                if(rowId==null){
                    showErrorDialog("", "请选择对应的强制工艺路线");
                    return;
                }
                var rowIds = domObj.grids.$glassListGrd.jqGrid("getGridParam","selarrrow");
                var data = new Array();
                for (var i=0;i<rowIds.length;i++){
                    var rowData = domObj.grids.$glassListGrd.jqGrid("getRowData",rowIds[i]);
                    data.push(rowData)
                }
                if (data.length<1) {
                    showErrorDialog("", "至少选中一条玻璃信息");
                    return false;
                }
                nx_path_id_fk = pathRowData.path_id;
                nx_path_ver_fk = pathRowData.path_ver;
                crPathIdFk = domObj.$crPathIdFk.val();
                if (!crPathIdFk) {
                    showErrorDialog("", "当前工艺路线不能为空");
                    return false;
                }
                crPathVerFk = domObj.$crPathVerFk.val();
                if (!crPathVerFk) {
                    showErrorDialog("", "当前工艺版本不能为空");
                    return false;
                }
                crOpeNoFk = domObj.$crOpeNoFk.val();
                if (!crOpeNoFk) {
                    showErrorDialog("", "当前站点不能为空");
                    return false;
                }
                if(domObj.buttons.$radioOne.prop('checked')){
                    swhTyp='R';
                }else if(domObj.buttons.$radioTwo.prop('checked')){
                    swhTyp='K';
                }else {
                    swhTyp='Q';
                }
                iary = {
                    box_id : boxId,
                    swh_typ: swhTyp,
                    nx_path_id_fk  : nx_path_id_fk,
                    nx_path_ver_fk : nx_path_ver_fk,
                    cr_path_id_fk  : crPathIdFk,
                    cr_path_ver_fk : crPathVerFk,
                    cr_ope_no_fk   : crOpeNoFk,
                    rsn_code       : rsnCode,
                    rsn_cate       : rsnCate,
                    rsn_dept       : rsnDept,
                    ret_prd_info   : data,
                    evt_usr        : VAL.EVT_USER,
                };
                inObj = {
                    trx_id : VAL.T_FPPFORCEIN,
                    action_flg : "F",
                    iary : [iary]
                };
                outObj = comTrxSubSendPostJson(inObj);
                if (outObj.rtn_code === VAL.NORMAL) {
                    domObj.dialogs.$forcePathDialog.modal("hide");
                    if(domObj.buttons.$radioOne.prop('checked')){
                        showSuccessDialog("强制进入修补成功");
                    }else if(domObj.buttons.$radioTwo.prop('checked')){
                        showSuccessDialog("强制进入重工成功");
                    }else {
                        showSuccessDialog("强制进入OQC成功");
                    }
                    btnFunc.queryBtnfunc();//更新信息
                }
            }
        }
        //页面切换方法
        var  radioFnc = {
            radioOneBtnfunc : function() {
                if(domObj.buttons.$radioOne.prop('checked')){
                    domObj.$boxIdFk.val("");
                    clearDataAction();
                    $("#swhDiv").show();
                    domObj.buttons.$selectReason_btn.hide();
                    domObj.buttons.$deleteReason_btn.hide();
                    domObj.grids.$reasonDiv.hide();
                    domObj.grids.$glassListGrd.setGridHeight($(window).height()*0.68);//设置高度
                    domObj.buttons.$sure_btn.show();
                    domObj.buttons.$sure_btn.html("修补");
                    domObj.buttons.$cancel_btn.html("取消修补");
                    domObj.buttons.$cancel_btn.show();
                    domObj.buttons.$force_btn.html("强制修补");
                    domObj.buttons.$stop_btn.html("终止修补");
                }
            },
            radioTwoBtnfunc: function() {
                if(domObj.buttons.$radioTwo.prop('checked')){
                    domObj.$boxIdFk.val("");
                    clearDataAction();
                    $("#swhDiv").hide();
                    domObj.buttons.$selectReason_btn.show();
                    domObj.buttons.$deleteReason_btn.show();
                    domObj.grids.$reasonDiv.show();
                    domObj.grids.$glassListGrd.setGridHeight($(window).height()*0.4);
                    domObj.buttons.$sure_btn.hide();
//                    domObj.buttons.$sure_btn.html("重工");
                    domObj.buttons.$cancel_btn.html("取消重工");
                    domObj.buttons.$cancel_btn.hide();
                    domObj.buttons.$force_btn.html("强制重工");
                    domObj.buttons.$stop_btn.html("终止重工");
                }
            },
            radioThreeBtnfunc: function() {
                if(domObj.buttons.$radioThere.prop('checked')){
                    domObj.$boxIdFk.val("");
                    clearDataAction();
                    $("#swhDiv").hide();
                    domObj.buttons.$selectReason_btn.hide();
                    domObj.buttons.$deleteReason_btn.hide();
                    domObj.grids.$reasonDiv.hide();
                    domObj.grids.$glassListGrd.setGridHeight($(window).height()*0.68);
//                    domObj.buttons.$sure_btn.html("OQC");
                    domObj.buttons.$sure_btn.hide();
                    domObj.buttons.$cancel_btn.html("取消OQC");
                    domObj.buttons.$cancel_btn.show();
                    domObj.buttons.$force_btn.html("强制OQC");
                    domObj.buttons.$stop_btn.html("终止OQC");
                }
            }
        }
        var iniButtonAction = function() {
            //radio click 事件
            domObj.buttons.$radioOne.click(function() {
                radioFnc.radioOneBtnfunc();
            });
            domObj.buttons.$radioTwo.click(function() {
                radioFnc.radioTwoBtnfunc();
            });
            domObj.buttons.$radioThere.click(function() {
                radioFnc.radioThreeBtnfunc();
            });

            //button click 事件
            domObj.buttons.$query_btn.click(function() {
                btnFunc.queryBtnfunc();
            });
            domObj.buttons.$selectReason_btn.click(function() {
                btnFunc.selectReasonBtnfunc();
            });
            domObj.buttons.$deleteReason_btn.click(function() {
                btnFunc.deleteReasonBtnfunc();
            });
            domObj.buttons.$sure_btn.click(function() {
                btnFunc.sureBtnfunc();
            });
            domObj.buttons.$cancel_btn.click(function() {
                btnFunc.cancelBtnfunc();
            });
            domObj.buttons.$force_btn.click(function() {
                btnFunc.forceBtnfunc();
            });
            domObj.buttons.$stop_btn.click(function() {
                btnFunc.stopBtnfunc();
            });

            // 确认按钮绑定click事件函数
            domObj.dialogs.$reasonDialog_sureBtn.unbind('click',
                dialogFnc.reasonSureFnc);
            domObj.dialogs.$reasonDialog_sureBtn.bind('click',
                dialogFnc.reasonSureFnc);

            // 确认按钮绑定click事件函数
            domObj.dialogs.$rePathDialog_sureBtn.unbind('click',
                dialogFnc.rePathSureFnc);
            domObj.dialogs.$rePathDialog_sureBtn.bind('click',
                dialogFnc.rePathSureFnc);

            domObj.dialogs.$forcePathDialog_sureBtn.unbind('click',
                dialogFnc.forcePathSureFnc);
            domObj.dialogs.$forcePathDialog_sureBtn.bind('click',
                dialogFnc.forcePathSureFnc);
        }
        var clearDataAction = function() {
            SelectDom.setSelect(domObj.$frPathIdFk, "");
            domObj.$boxId.val("");
            domObj.$boxStat.val("");
            domObj.$prdQty.val("");
            domObj.$chipQty.val("");
            domObj.$crPathIdFk.val("");
            domObj.$crPathVerFk.val("");
            domObj.$crOpeNoFk.val("");
            domObj.$nxPathIdFk.val("");
            domObj.$nxPathVerFk.val("");
            domObj.$nxOpeNoFk.val("");
            domObj.$acRecipeId.val("");
            domObj.$woIdFk.val("");
            $("#reasonListGrd").jqGrid('clearGridData');
            $("#glassListGrd").jqGrid('clearGridData');
            $("#modalReasonListDiv").jqGrid('clearGridData');
            $("#reModalReasonListDiv").jqGrid('clearGridData');
            $("#rePathListDiv").jqGrid('clearGridData');
        }
        var otherActionBind = function(){
            //Stop from auto commit
            $("form").submit(function(){
                return false;
            });

        };
        var buttonText =  function(){
            domObj.buttons.$radioOne.prop('checked',true);
            domObj.buttons.$selectReason_btn.hide();
            domObj.buttons.$deleteReason_btn.hide();
            domObj.buttons.$sure_btn.html("修补");
            domObj.buttons.$cancel_btn.html("取消修补");
            domObj.buttons.$force_btn.html("强制修补");
            domObj.buttons.$stop_btn.html("终止修补");
            domObj.grids.$reasonDiv.hide();
            domObj.grids.$glassListGrd.setGridHeight($(window).height()*0.68);
        };
        domObj.$boxIdFk.keydown(function(event) {
            if (event.which == 13) {
                btnFunc.queryBtnfunc();
            }
        });
        $(window).resize(function(){
            $(window).unbind("onresize");
            //$("#keyword_detail").setGridHeight($(window).height() - 190);
            $(window).bind("onresize", this);
        });
        function initFunc() {
            domObj.$boxIdFk.val("");
            domObj.$boxIdFk.focus();
            clearDataAction();
            otherActionBind();
            iniButtonAction();
            iniGridInfo();
            inModelGrid();// 初始化dailog中的grids
            buttonText();//加载默认button按钮显示
        }
        initFunc();
        //模态框拖动
        $(".modal-content").draggable();
        //表格自适应
        function resizeFnc(){
            var offsetBottom, grdDivWidth;
            grdDivWidth = $("#divRight").width();
            offsetBottom = $(window).height() - $("#glassListDiv").offset().top;
            $("#glassListDiv").width(grdDivWidth*0.98);
            $("#glassListDiv").height(offsetBottom*0.99);
            $("#glassListGrd").setGridWidth(grdDivWidth*0.97);
            $("#glassListGrd").setGridHeight(offsetBottom*0.95-51);


        };
        resizeFnc();
        $(window).resize(function() {
            resizeFnc();
        });

    })
